package com.dabai.sas

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.dabai.sas.activitys.*
import com.dabai.sas.databinding.ActivityMainBinding
import com.dabai.sas.utils.DabaiUtils
import com.dabai.sas.utils.DebugUtils
import com.tencent.bugly.crashreport.CrashReport


class MainActivity : AppCompatActivity() {


    lateinit var activityMainBinding: ActivityMainBinding;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        activityMainBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(activityMainBinding.root)

        init()
    }

    @SuppressLint("SetTextI18n")
    private fun init() {

        /*
        设置 / 小工具
         */
        activityMainBinding.permissionToApplyFor.setOnClickListener {
            startActivity(Intent(this, PermissionsActivity::class.java))
        }

        activityMainBinding.about.setOnClickListener {
            startActivity(Intent(this, AboutActivity::class.java))
        }

        activityMainBinding.baseEncode.setOnClickListener {
            startActivity(Intent(this, BaseEncodeActivity::class.java))
        }
        activityMainBinding.moreFunctions.setOnClickListener {
            DabaiUtils().openLink(
                this,
                "https://support.qq.com/products/319062/blog/504746"
            )
        }


        /*
        开发调试
         */
        activityMainBinding.dev1.setOnClickListener {
            val info = """
            机型:${Build.MODEL}
            BOARD:${Build.BOARD}
            Android版本:${Build.VERSION.RELEASE}
            Android API:${Build.VERSION.SDK_INT}
            
            打开scheme:http的应用(${DabaiUtils.getBrowserList(this).size}):
            
            ${DabaiUtils.getBrowserList(this)}
            
            打开mime:image/*的应用(${DabaiUtils.getMimeSupportOpenSoftwares(this, "image/*").size}):
            
            ${DabaiUtils.getMimeSupportOpenSoftwares(this, "image/*")}

            打开mime:application/pdf的应用(${
                DabaiUtils.getMimeSupportOpenSoftwares(
                    this,
                    "application/pdf"
                ).size
            }):
            
            ${DabaiUtils.getMimeSupportOpenSoftwares(this, "application/pdf")}

        """.trimIndent()

            DebugUtils(this).showDebugMessage(info)
        }
        activityMainBinding.dev2.setOnClickListener {
            val info =
                """
        数据目录:${applicationInfo.dataDir}
        
        appdata_设备名:${DabaiUtils.getDeviceName(this)}
        appdata_设备id:${DabaiUtils.getDeviceID(this)}
        
        版本名称:${DabaiUtils().getVersionName(this)}
        版本号:${DabaiUtils().getVersionCode(this)}
            
        所有Activity(${DabaiUtils().getActivitysName(this).size}):
        
        ${DabaiUtils().getActivitysName(this)}
        """.trimIndent()

            DebugUtils(this).showDebugMessage(info)
        }
        activityMainBinding.dev3.setOnClickListener {
            CrashReport.testJavaCrash()
        }

        activityMainBinding.dev5.setOnClickListener {
            startActivity(Intent(this, BrowserActivity::class.java))
        }


    }

}